from django.db import models
from mlh.utils.model import BaseModel
from users.models import User


# Create your models here.


class Spit(BaseModel):
    COLLECTION_ENUM = {
        "UNCOLLECT": 1,
        "COLLECTED": 2
    }

    COLLECTION_CHOICES = (
        (1, "未收藏"),
        (2, "已收藏"),
    )

    digested = models.CharField(max_length=200, null=True, verbose_name='摘要')
    source = models.CharField(max_length=10, verbose_name='来源')
    like_count = models.IntegerField(default=0, verbose_name='点赞次数')
    user = models.ForeignKey(User, null=True, on_delete=models.CASCADE, related_name='spit', verbose_name='用户')
    content = models.TextField(verbose_name='吐槽内容')
    collection_status = models.SmallIntegerField(choices=COLLECTION_CHOICES, default=1, verbose_name='收藏状态')
    clicks = models.IntegerField(default=0, verbose_name='点击次数')

    class Meta:
        db_table = 'tb_spits'
        verbose_name = '吐槽模板'
        verbose_name_plural = '吐槽模板'

    def __str__(self):
        return self.digested


class UserCollection(BaseModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='collections', verbose_name='用户')
    spit = models.ForeignKey(Spit, verbose_name='吐槽')

    class Meta:
        db_table = 'tb_user_collection'
        verbose_name = '吐槽收藏'
        verbose_name_plural = '吐槽收藏'


class Comment(BaseModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='comments', verbose_name='用户')
    spit = models.ForeignKey(Spit, verbose_name='吐槽')
    contents = models.CharField(max_length=200, verbose_name='评论')
    com_like_count = models.IntegerField(default=0, null=True, verbose_name='评论点赞')

    class Meta:
        db_table = 'tb_comment'
        verbose_name = '吐槽评论'
        verbose_name_plural = '吐槽评论'
